#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void resver_word(char arr[], int lo, int hi)
{
    for (int i = lo, j = hi; i < j; ++i, --j) {
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }

    int s = lo;
    int e = s;

    while(s < hi) {
        e = s;

        while(arr[e] != ' ' && e <= hi) {
            e++;
        }

        for (int i = s, j = e - 1; i < j; ++i, --j) {
            arr[i] = arr[i] ^ arr[j];
            arr[j] = arr[i] ^ arr[j];
            arr[i] = arr[i] ^ arr[j];
        }

        s = e;

        while (s <= hi && arr[s] == ' ') {
            s++;
        }
    }
}


int main(int argc, const char *argv[])
{
    char arr[] = "I am a student.";
    printf("%s %d\n", arr, strlen(arr));
    resver_word(arr, 0, strlen(arr) - 1);
    printf("%s", arr);
    return 0;
}
